<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="套餐名称" prop="packageName">
        <el-input
          v-model="queryParams.packageName"
          placeholder="请输入套餐名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="套餐助记码" label-width="100px" prop="packageProjectcode">
        <el-input
          v-model="queryParams.packageProjectcode"
          placeholder="请输入套餐助记码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="套餐类别" prop="packageCategory">
        <el-input
          v-model="queryParams.packageCategory"
          placeholder="请输入套餐类别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="一级分类" prop="primaryClassification">-->
<!--        <el-input-->
<!--          v-model="queryParams.primaryClassification"-->
<!--          placeholder="请输入一级分类"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="二级分类" prop="twoLevelClassification">-->
<!--        <el-input-->
<!--          v-model="queryParams.twoLevelClassification"-->
<!--          placeholder="请输入二级分类"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="三级分类" prop="thirdLevelClassification">-->
<!--        <el-input-->
<!--          v-model="queryParams.thirdLevelClassification"-->
<!--          placeholder="请输入三级分类"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="创建人姓名" prop="creatorName">-->
<!--        <el-input-->
<!--          v-model="queryParams.creatorName"-->
<!--          placeholder="请输入创建人姓名"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="创建人ID" prop="creatorId">-->
<!--        <el-input-->
<!--          v-model="queryParams.creatorId"-->
<!--          placeholder="请输入创建人ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="创建时间" prop="creatorTime">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.creatorTime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择创建时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="mealList"  ref="singleTable"  height="546"
              border
              :row-style="{height:'50px'}"
              :cell-style="{textAlign: 'center'}"
              style="width: 100%">
      <el-table-column prop="number" label="序号" width="100" align="center"  type="index" :ixdex="indexMethod"></el-table-column>
      <el-table-column label="套餐名称" width="200"  align="center" prop="packageName" />
      <el-table-column label="套餐水号" width="200" align="center" prop="packageProjectcode" />
<!--      <el-table-column label="套餐类别" width="200" align="center" prop="packageCategory" />-->
<!--      <el-table-column label="一级分类" align="center" prop="primaryClassification" />-->
<!--      <el-table-column label="二级分类" align="center" prop="twoLevelClassification" />-->
<!--      <el-table-column label="三级分类" align="center" prop="thirdLevelClassification" />-->
      <el-table-column label="套餐状态"width="200"  align="center" prop="packageStatus" >
        <template scope="scope">
          <span v-if="scope.row.packageStatus==='0'" style="color: red"><el-tag style="width: 100px" type="success" >正常</el-tag></span>
          <span v-else-if="scope.row.packageStatus==='1'" style="color: red"><el-tag style="width: 100px" type="danger">停用</el-tag></span>
        </template>
      </el-table-column>
      <el-table-column label="创建人姓名" width="200"  align="center" prop="creatorName" />
      <el-table-column label="创建时间" align="center" prop="creatorTime" width="300">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.creatorTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            type="success"
            plain
            @click="chakan(scope.row)"
          >查看套餐</el-button>
<!--          <el-button-->
<!--            type="warning"-->
<!--            plain-->
<!--            @click="handleUpdate(scope.row)"-->
<!--          >修改套餐</el-button>-->
          <el-button
            type="danger"
            plain
            @click="handleDelete(scope.row)"
          >删除套餐</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改套餐信息对话框 -->
<!--    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>-->
<!--      <el-form ref="form" :model="form" :rules="rules" label-width="80px">-->
<!--        <el-form-item label="套餐名称" prop="packageName">-->
<!--          <el-input v-model="form.packageName" placeholder="请输入套餐名称" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="套餐助记码" prop="packageProjectcode">-->
<!--          <el-input v-model="form.packageProjectcode" placeholder="请输入套餐助记码" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="套餐类别" prop="packageCategory">-->
<!--          <el-input v-model="form.packageCategory" placeholder="请输入套餐类别" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="一级分类" prop="primaryClassification">-->
<!--          <el-input v-model="form.primaryClassification" placeholder="请输入一级分类" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="二级分类" prop="twoLevelClassification">-->
<!--          <el-input v-model="form.twoLevelClassification" placeholder="请输入二级分类" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="三级分类" prop="thirdLevelClassification">-->
<!--          <el-input v-model="form.thirdLevelClassification" placeholder="请输入三级分类" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="创建人姓名" prop="creatorName">-->
<!--          <el-input v-model="form.creatorName" placeholder="请输入创建人姓名" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="创建人ID" prop="creatorId">-->
<!--          <el-input v-model="form.creatorId" placeholder="请输入创建人ID" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="创建时间" prop="creatorTime">-->
<!--          <el-date-picker clearable-->
<!--            v-model="form.creatorTime"-->
<!--            type="date"-->
<!--            value-format="yyyy-MM-dd"-->
<!--            placeholder="请选择创建时间">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
<!--      </el-form>-->
<!--      <div slot="footer" class="dialog-footer">-->
<!--        <el-button type="primary" @click="submitForm">确 定</el-button>-->
<!--        <el-button @click="cancel">取 消</el-button>-->
<!--      </div>-->
<!--    </el-dialog>-->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form label-position="right" ref="form" :model="form"  :rules="rules"  label-width="120px">
        <el-container>

          <el-header>
            <el-divider content-position="left">
              <p style="color: #00afff; font-size: 18px;">套餐详细</p>
            </el-divider>
          </el-header>
          <el-table v-loading="loading" :data="associationList"  ref="singleTable"
                    border
                    :cell-style="{textAlign: 'center'}"
                   style="width: 63%;margin-left: 18%"
          >
            <el-table-column
              prop="entryName"
              align="center"
              label="名称"
              width="180">
            </el-table-column>
            <el-table-column
              prop="projectCode"
              align="center"
              label="助记码"
              width="180">
            </el-table-column>
            <el-table-column
              prop="unitPrice"
              align="center"
              label="单价"
              width="180">
            </el-table-column>
          </el-table>
        </el-container>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import { listProject, getProject, delProject, addProject, updateProject } from "@/api/module/shao/project";
  import { listMeal, getMeal, delMeal, addMeal, updateMeal } from "@/api/module/shao/meal";
  import { listAssociation, getAssociation, delAssociation, addAssociation, updateAssociation } from "@/api/module/shao/association";


export default {
  name: "Meal",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      projectListtao:[],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 套餐信息表格数据
      mealList: [],
      associationList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form1: {},
      // 查询参数
      association: {
        pageNum: 1,
        pageSize: 10,
        setMealId: null,
        projectId: null,
        creationTime: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      },
      // 表单参数
      assform: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        packageName: null,
        packageProjectcode: null,
        packageCategory: null,
        primaryClassification: null,
        twoLevelClassification: null,
        thirdLevelClassification: null,
        packageStatus: null,
        creatorName: null,
        creatorId: null,
        creatorTime: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //查看套餐
    chakan(row){
      const a=row.packageProjectcode;
      this.association.setMealId=a;
      listAssociation(this.association).then(response => {
        this.associationList = response.rows;
        this.title="查看套餐详细"
        this.open=true;
      });


    },
    // 生成表头序号
    indexMethod(index){
      return index+1;
      this.xuhao=index+1;
    },
    /** 查询套餐信息列表 */
    getList() {
      this.loading = true;
      listMeal(this.queryParams).then(response => {
        this.mealList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        packageName: null,
        packageProjectcode: null,
        packageCategory: null,
        primaryClassification: null,
        twoLevelClassification: null,
        thirdLevelClassification: null,
        packageStatus: null,
        creatorName: null,
        creatorId: null,
        creatorTime: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加套餐信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // this.reset();
      // const id = row.id || this.ids
      // getMeal(id).then(response => {
      //   this.form = response.data;
      //   this.open = true;
      //   this.title = "修改套餐信息";
      // });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateMeal(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMeal(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否删除该套餐？').then(function() {
        return delMeal(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('project/meal/export', {
        ...this.queryParams
      }, `meal_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
